package pe.edu.upc.dsd.rs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConexionPgSQL {
	 	private Connection conn;
	    private ResultSet rs;
	    public String s;

	    public void ConexionPgsql() {
	        String url="";
	        try {
	            Class.forName("org.postgresql.Driver");
	            url="jdbc:postgresql://localhost/perfil-psicologico";
	            try {
	                conn = DriverManager.getConnection(url, "pgsql", "kasuya");
	            } catch (SQLException ex) {
	                Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
	            }
	        } catch (ClassNotFoundException ex) {
	            Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
	        }
	    }

	    public void QuerySQL(String sqlQuery) {
	        try {
	            rs = this.getConn().createStatement().executeQuery(sqlQuery);
	        } catch (SQLException ex) {
	            Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
	        }
	    }

	    public void QueryInsertSQL(String sqlQuery) {
	        try {
	            //this.getConn().createStatement().executeQuery(sqlQuery);
	            this.getConn().createStatement().execute(sqlQuery);

	        } catch (SQLException ex) {
	            Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
	        }
	    }

	    public void QueryUpdateSQL(String sqlQuery) {
	        try {
	            //this.getConn().createStatement().executeQuery(sqlQuery);
	            this.getConn().createStatement().execute(sqlQuery);

	        } catch (SQLException ex) {
	            Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
	        }
	    }

	    public void CloseConnection() throws SQLException {
	        this.getConn().close();
	    }

	    /**
	     * @return the conn
	     */
	    public Connection getConn() {
	        return conn;
	    }

	    /**
	     * @return the rs
	     */
	    public ResultSet getRs() {
	        return rs;
	    }
}
